﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fynd.Hermes.Web.Objects;
using FyndSharp.Data;
using FyndSharp.Data.Orm;
using System.Data.Common;
using System.Data;

namespace Fynd.Hermes.Web.Pages
{
    public partial class UserList : RoleBasedPage
    {
        protected List<UserInfomation> ResultList = new List<UserInfomation>();
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadResult();
        }

        private void LoadResult()
        {
            AdoSession db = AdoSessionManager.Current["hermes"];
            bool isDbOpen = false;
            try
            {
                isDbOpen = db.Open();

                string sql = OrmObjectFactory.CreateSelectSql(typeof(UserInfomation));
                sql += " ORDER BY created_date DESC";
                using (DbCommand cmd = db.CreateCommand(sql))
                {
                    DataTable dt = db.ExecuteDataTable(cmd);
                    foreach (DataRow row in dt.Rows)
                    {
                        ResultList.Add(OrmObjectFactory.CreateOrmObject<UserInfomation>(row));
                    }
                }
            }
            finally
            {
                if (isDbOpen)
                {
                    db.Close();
                }
            }
        }

        protected override IEnumerable<UserRole> AccreditedRoles
        {
            get {
                return new UserRole[] { UserRole.Administrator };
            }
        }
    }
}